﻿using System;
using System.Collections.Generic;

namespace ProblemsSet
{
    public class Problem_142 : BaseProblem
    {
        public override object GetResult()
        {
            for (long aa = 5; aa < long.MaxValue; aa++)
            {
                long a = aa*aa;
                for (long dd = 1; dd < aa; dd++)
                {
                    long d = dd*dd;
                    for (long bb = 1; bb < dd; bb++)
                    {
                        long b = bb*bb;
                        if ((a+b)%2!=0)
                            continue;
                        long x = (a + b)/2;
                        long y = (a - b) / 2;
                        long z = x - d;
                        if (z <= 0 || z >= y) continue;
                        if (!MathLogic.IsSquare(x+z))
                            continue;
                        if (!MathLogic.IsSquare(y + z))
                            continue;
                        if (!MathLogic.IsSquare(y - z))
                            continue;
                        return x + y + z;
                    }
                }
            }
            return -1;

        }

        public override string Problem
        {
            get
            {
                return @"Find the smallest x + y + z with integers x  y  z  0 such that x + y, x  y, x + z, x  z, y + z, y  z are all perfect squares.";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 1006193;
            }
        }

    }
}
